﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Common;
using WinnerCMS.Data;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 主数据管理业务逻辑类
    /// </summary>
    public class MasterDataManage<T> where T : class, IMasterData
    {
        private static readonly MasterDataDal<T> Dal = new MasterDataDal<T>();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public Result Add(T model)
        {
            Result resu = new Result();
            if (model.Name.Length == 0)
            {
                resu.Errors = "“名称”不能为空！";
                return resu;
            }


            if (model.Code.IsNullOrEmpty())
            {
                Dal.Add(model);
            }
            else
            {
                Dal.Edit(model);
            }
            return resu;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public Result Delete(string[] codes)
        {
            Result res = new Result();
            if (codes.Length == 0)
            {
                res.Errors = "至少选择一项。";
                return res;
            }
            Dal.Delete(codes);
            return res;
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="code"></param>
        public T GetInfo(string code)
        {
            return Dal.GetInfo(code);
        }

        #endregion

        #region 取得下级数据

        /// <summary>
        /// 取得下级数据
        /// </summary>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        public IList<T> GetData(string parentCode)
        {
            return Dal.GetData(parentCode);
        }

        #endregion
    }
}